import 'package:flutter/material.dart';

class MyTableElement extends StatefulWidget {
  // 传入参数
  const MyTableElement({
    Key? key,
    required this.checkName,
    required this.checkDept,
    required this.checkTime,
    required this.result,
    required this.onTap,
    required this.reportContent,
    required this.tag,
  }) : super(key: key,);
  final String checkName;
  final String checkDept;
  final String checkTime;
  final String result;
  final VoidCallback onTap;
  final Map reportContent;
  final String tag;

  @override
  State<StatefulWidget> createState() => MyTableElementState();
}

class MyTableElementState extends State<MyTableElement> {
  List<String> choices = ['OK','NG'];
  Map choicesValues = {'OK':'合格','NG':'不合格'};
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {widget.onTap();},
      child:
      Stack(
          alignment: AlignmentDirectional.center,//指定未定位或部分定位的子组件的对齐方式
          children: <Widget>[
            Container(
                padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
                child: Container(
                    padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    decoration: BoxDecoration(
                      border: Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) ),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: widget.reportContent.length == 0 ? [
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查人员 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkName +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '所属部门 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkDept +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查结果 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.result +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查时间 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkTime +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                      ]:[
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '标准值(kgf.cm) ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['standard'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '实测值(kgf.cm) ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['reality'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '调校值(kgf.cm) ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['adjust'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '对地电阻(Ω)(标准≤10) ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['ohm'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '外观及电源线 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: choices.contains(widget.reportContent['exterior'].toString()) ?choicesValues[widget.reportContent['exterior'].toString()]:' ',
                                            style: widget.reportContent['exterior'].toString()=='NG'?TextStyle(
                                                fontSize:13,
                                                backgroundColor: Colors.redAccent,
                                                color: Colors.yellow
                                            ):TextStyle(
                                                fontSize:13,
                                                color: Colors.black87
                                            ),
                                          ),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '扭力保护套 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [

                                          TextSpan( text: choices.contains(widget.reportContent['sheath'].toString()) ?choicesValues[widget.reportContent['sheath'].toString()]:' ',
                                            style: widget.reportContent['sheath'].toString()=='NG'?TextStyle(
                                                fontSize:13,
                                                backgroundColor: Colors.redAccent,
                                                color: Colors.yellow
                                            ):TextStyle(
                                                fontSize:13,color: Colors.black87
                                            ),
                                          ),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '保养时间 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['mainTime'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '使用岗位 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.reportContent['role'].toString() +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查人员 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkName +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '所属部门 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkDept +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                flex: 3,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查结果 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 2,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: choices.contains(widget.result.toString()) ?choicesValues[widget.result.toString()]:' ',
                                            style: widget.result.toString()=='NG'?TextStyle(
                                                fontSize:13,
                                                backgroundColor: Colors.redAccent,
                                                color: Colors.yellow
                                            ):TextStyle(
                                                fontSize:13,
                                                color: Colors.black87
                                            ),
                                          ),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: '检查时间 ', style: TextStyle(fontSize:10,color: Colors.black38,fontWeight: FontWeight.w500),),
                                        ]
                                    )
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child:Text.rich(
                                    TextSpan(
                                        children: [
                                          TextSpan( text: ' ' + widget.checkTime +' ',style: TextStyle(fontSize:13,color: Colors.black87),),
                                        ]
                                    )
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.fromLTRB(2, 2, 2, 2),
                        ),
                      ],
                    )
                )
            ),
            Positioned(
                top: 0,
                right: 5,
                child: Container(
                  padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
                  decoration: BoxDecoration(
                    color: widget.tag== ' 未检验 '?Colors.redAccent:Colors.lightBlueAccent ,
                    borderRadius: BorderRadius.circular(0),
                    // border: new Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) ),
                  ),
                  child: Text(widget.tag,
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.w600,fontSize: 15),
                  ),
                )
            ),
          ])

    );
  }
}